package com.edu.juc.collections.map;

import java.util.HashMap;

public class HashMapTest {
    public static void main(String[] args) {
        // ConcurrentHashMap 解决 HashMap 的线程安全问题
//        ConcurrentHashMap<Integer, Integer> map = new ConcurrentHashMap<>();
        HashMap<Integer, Integer> map = new HashMap<>();
        new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                map.put(i, i);
            }
            System.out.println("map.size() = " + map.size());
        }, "1").start();
        new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                map.put(i, i);
            }
            System.out.println("map.size() = " + map.size());
        }, "2").start();
    }
}
